package com.somnus.androidkotlindemo.adapter

import android.support.v7.util.DiffUtil
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.somnus.androidkotlindemo.R
import com.somnus.androidkotlindemo.callback.DiffUtilsCallback
import kotlinx.android.synthetic.main.item_recycler.view.*


/**
 * Created by Somnus on 2019/5/22.
 */

class DiffUtilsAdapter : BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_top_recycler) {

//    var mList: List<String>? = null
//
//    public fun DiffData(mList: List<String>) {
//        this.mList = mList
//    }

//    constructor(list: List<String>) : super(R.layout.item_top_recycler, list) {
//        this.mList = list
//    }


    override fun convert(helper: BaseViewHolder?, item: String?) {
        with(helper?.itemView!!) {
            textView3.text = data.get(helper.layoutPosition)
        }
    }

    fun setDiffList(list: MutableList<String>) {
        if (emptyViewCount == 1) {
            // 如果当前显示的是空视图，则不进行diff，直接设置新数据
            setNewData(list)
            return
        }
        val diffResult = DiffUtil.calculateDiff(DiffUtilsCallback(mData, list))
        diffResult.dispatchUpdatesTo(this)
        mData = list
    }

}
